//
// Created by Crestimes on 24-6-8.
//
#include <iostream>

#include "BaseAlgorithm.h"
#include "FIFO.h"
#include "LRU.h"
#include "OPT.h"

using namespace std;

void start(BaseAlgorithm* algo, const bool& verbose = false) {
    algo->start(verbose); // 启动算法，可以选择是否显示中间日志
    cout << endl;
}

int main() {
    // 给定的页号序列
    const vector<int> pageList = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1};
    // 内存块的最大数量
    constexpr int maxSize = 3;

    // 创建页面置换算法实例
    auto* fifo = new FIFO(pageList, maxSize);
    auto* lru = new LRU(pageList, maxSize);
    auto* opt = new OPT(pageList, maxSize);

    // 运行算法并打印结果
    start(fifo, true); // 显示FIFO算法的中间日志
    start(lru); // 不显示LRU算法的中间日志
    start(opt); // 显示OPT算法的中间日志

    // 释放算法实例
    delete fifo;
    delete lru;
    delete opt;

    return 0;
}

// output
/*
--------------- FIFO ------------------
FIFO process:
[0] 	input: 7 		 7    		+
[1] 	input: 0 		 7 0  		+
[2] 	input: 1 		 7 0 1		+
[3] 	input: 2 		 0 1 2		+
[4] 	input: 0 		 0 1 2
[5] 	input: 3 		 1 2 3		+
[6] 	input: 0 		 2 3 0		+
[7] 	input: 4 		 3 0 4		+
[8] 	input: 2 		 0 4 2		+
[9] 	input: 3 		 4 2 3		+
[10] 	input: 0 		 2 3 0		+
[11] 	input: 3 		 2 3 0
[12] 	input: 2 		 2 3 0
[13] 	input: 1 		 3 0 1		+
[14] 	input: 2 		 0 1 2		+
[15] 	input: 0 		 0 1 2
[16] 	input: 1 		 0 1 2
[17] 	input: 7 		 1 2 7		+
[18] 	input: 0 		 2 7 0		+
[19] 	input: 1 		 7 0 1		+
---------------------------------------
OutPageList: 7 0 1 2 3 0 4 2 3 0 1 2
Limit ratio: 0.750
---------------------------------------

--------------- LRU ------------------
LRU process:
[0] 	input: 7 		 7    		+
[1] 	input: 0 		 7 0  		+
[2] 	input: 1 		 7 0 1		+
[3] 	input: 2 		 2 0 1		+
[4] 	input: 0 		 2 0 1
[5] 	input: 3 		 2 0 3		+
[6] 	input: 0 		 2 0 3
[7] 	input: 4 		 4 0 3		+
[8] 	input: 2 		 4 0 2		+
[9] 	input: 3 		 4 3 2		+
[10] 	input: 0 		 0 3 2		+
[11] 	input: 3 		 0 3 2
[12] 	input: 2 		 0 3 2
[13] 	input: 1 		 1 3 2		+
[14] 	input: 2 		 1 3 2
[15] 	input: 0 		 1 0 2		+
[16] 	input: 1 		 1 0 2
[17] 	input: 7 		 1 0 7		+
[18] 	input: 0 		 1 0 7
[19] 	input: 1 		 1 0 7
---------------------------------------
OutPageList: 7 1 2 3 0 4 0 3 2
Limit ratio: 0.600
---------------------------------------

--------------- OPT ------------------
OPT process:
[0] 	input: 7 		 7    		+
[1] 	input: 0 		 7 0  		+
[2] 	input: 1 		 7 0 1		+
[3] 	input: 2 		 2 0 1		+
[4] 	input: 0 		 2 0 1
[5] 	input: 3 		 2 0 3		+
[6] 	input: 0 		 2 0 3
[7] 	input: 4 		 2 4 3		+
[8] 	input: 2 		 2 4 3
[9] 	input: 3 		 2 4 3
[10] 	input: 0 		 2 0 3		+
[11] 	input: 3 		 2 0 3
[12] 	input: 2 		 2 0 3
[13] 	input: 1 		 2 0 1		+
[14] 	input: 2 		 2 0 1
[15] 	input: 0 		 2 0 1
[16] 	input: 1 		 2 0 1
[17] 	input: 7 		 7 0 1		+
[18] 	input: 0 		 7 0 1
[19] 	input: 1 		 7 0 1
---------------------------------------
OutPageList: 7 1 0 4 3 2
Limit ratio: 0.450
---------------------------------------
*/
